﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OgilvyOne.BLL;
using OgilvyOne.Model;

public partial class admin_infomation_article_select : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            string articles = Request.Params["concacts"];
            ListBox1.Items.Clear();
            CmsArticleBll catb = new CmsArticleBll();
            CmsArticleQuery q = new CmsArticleQuery();
            q.layerid = "1,2,17,44,267,269";
            IList ls = catb.getCmsArticleList(q);
            this.ListBox1.DataSource = ls;
            this.ListBox1.DataTextField = "Title";
            this.ListBox1.DataValueField = "Articleid";
            this.ListBox1.DataBind();
            this.Button5.Attributes.Add("onclick", "window.close()");
            if (articles != null && articles.Trim() != "")
            {
                string[] tags = articles.Split(',');
                for (int i = 0; i < tags.Length; i++)
                {
                    for (int j = 0; j < ListBox1.Items.Count; j++)
                    {
                        string us = tags[i].ToString();
                        if (ListBox1.Items[j].Value.ToString() == us)
                        {
                            ListItem lit = new ListItem(ListBox1.Items[j].Text.ToString(), ListBox1.Items[j].Value.ToString());
                            ListBox2.Items.Add(lit);
                            ListBox1.Items.Remove(ListBox1.Items[j]);
                            ListBox2.SelectedIndex = -1;
                        }
                    }
                }
            }
            else
            {

            }

            IList cyslist = new ColumnBll().GetColumnList(269);
            for (int i = 0; i < cyslist.Count; i++)
            {
                ColumnModel cm = (ColumnModel)cyslist[i];
                cys.Items.Add(new ListItem(cm.Classname, cm.Classid.ToString()));
            }
        }
    }
    //搜索按钮
    protected void Search_Click(object sender, EventArgs e)
    {
        ListBox1.Items.Clear();
        CmsArticleBll catb = new CmsArticleBll();
        CmsArticleQuery q = new CmsArticleQuery();
        q.layerid = "1,2,17,44,267,269";
        
        if (name.Text != null && name.Text.ToString().Trim() != "")
        {
            q.querykey = "Title";
            q.queryvalue = name.Text;
            q.querytype = "2";
        }
        if (cys.SelectedValue != null && cys.SelectedValue != "")
        {
            q.columnid = int.Parse(cys.SelectedValue);
        }
        IList ls = catb.getCmsArticleList(q);
        this.ListBox1.DataSource = ls;
        this.ListBox1.DataTextField = "Title";
        this.ListBox1.DataValueField = "Articleid";
        this.ListBox1.DataBind();
    }
    //选择
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ListBox1.SelectedIndex != -1)
        {
            ListBox2.Items.Add(ListBox1.SelectedItem);
            ListBox1.Items.Remove(ListBox1.SelectedItem);
            ListBox2.SelectedIndex = -1;
        }
        else
        {
            ListBox1.SelectedIndex = 0;
        }
    }
    //删除
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (ListBox2.SelectedIndex != -1)
        {
            ListBox1.Items.Add(ListBox2.SelectedItem);
            ListBox2.Items.Remove(ListBox2.SelectedItem);
            ListBox1.SelectedIndex = -1;
        }
        else
        {
            ListBox2.SelectedIndex = 0;
        }
    }
    //确定
    protected void Button4_Click(object sender, EventArgs e)
    {

    }
}
